﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Data.Objects;
using System.Data.Entity;
using System.Data;
using System.Data.Linq;
using System.Data.EntityClient;
using System.Data.Query;
using System.Linq;
using System.Linq.Expressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Arquitetura.Architectural.Model;
using Arquitetura.Model;

namespace Arquitetura.Model.Test
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class AlunoTestUnit
    {
        public AlunoTestUnit()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        private static string GenerateNome(string prefixo)
        {
            return prefixo + " Nome Teste " + DateTime.Now.Ticks.ToString();
        }

        private static string GenerateSobrenome(string prefixo)
        {
            return prefixo + " Sobrenome Teste " + DateTime.Now.Ticks.ToString();
        }

        [TestMethod]
        public void TestMethod1()
        {

            //ArquiteturaModelContainer amc = new ArquiteturaModelContainer();
            //amc.PessoaSet.MergeOption = MergeOption.NoTracking;
            //string query = ;
                
                
                
            //    "SELECT VALUE Mae FROM PessoaSet AS Mae WHERE VALUE is Mae";


            //ObjectQuery<Mae> maes = new ObjectQuery<Mae>(query, amc).Include("Filho");
            //var mae = (from qmae in maes
            //           where qmae.Id == 200
            //           select qmae).First();


            //foreach (Aluno alu in mae.Filho)
            //{
            //    Console.Write(alu.Nome);
            //}

            //Aluno aluno = new Aluno();
            //Mae lastMaeRead = new Mae() { Id = 200 };
            //aluno.Mae = lastMaeRead;

            //amc.PessoaSet.MergeOption = MergeOption.OverwriteChanges;

            //aluno.Nome = GenerateNome("Aluno");
            //aluno.Sobrenome = GenerateSobrenome("Aluno");
            //aluno.Mae = null;
            //aluno.MaeReference.EntityKey = new EntityKey(amc.DefaultContainerName + ".PessoaSet", "Id", lastMaeRead.Id);
            //amc.PessoaSet.InsertEntity(aluno, "PessoaSet");


            //Mae lastMae = (from pessoa in amc.PessoaSet
            //               where pessoa is Mae
            //               orderby pessoa.Id descending
            //               select pessoa as Mae).First();

            //aluno = new Aluno();
            //aluno.Nome = GenerateNome("Aluno");
            //aluno.Sobrenome = GenerateSobrenome("Aluno");
            //aluno.Mae = lastMae;
            //amc.PessoaSet.InsertEntity(aluno, "PessoaSet");
        }
    }
}
